<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://a42.vodafone.com/versions/all/v1.0"
    xmlns:tns="http://a42.vodafone.com/versions/all/v1.0"
    elementFormDefault="qualified"
>

    <!-- XML schema 1.0 legacy!!! -->

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Definition of XML representations for common A42 resources and related DTOs. -->
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- Base type for all kinds of representations that allows for extensions that don't break existing clients on validation. -->
    <xs:complexType abstract="true" name="ExtensibleType">
        <xs:sequence>
            <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
        </xs:sequence>
        <xs:anyAttribute namespace="##other" processContents="lax" />
    </xs:complexType>

    <!-- A generic (key, value) pair. -->
    <xs:complexType name="KeyValueType">
        <!-- <xs:element name="value" type="xs:string" minOccurs="1" maxOccurs="1" /> -->
        <xs:attribute name="key" type="xs:string" use="required" />
        <xs:attribute name="value" type="xs:string" use="required" />
    </xs:complexType>

    <!-- A collection of (key, value) pairs that can be used to provide arbitrary details for whatever. -->
    <xs:complexType name="KeyValueCollectionType">
        <xs:sequence>
            <xs:element name="keyValue" type="tns:KeyValueType" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>

    <!-- All kinds of generic link types. -->
    <xs:complexType name="LinkType">
        <xs:attribute name="rel" type="xs:string" use="optional" />
        <xs:attribute name="href" type="xs:anyURI" use="required" />
        <xs:attribute name="method" type="xs:string" use="optional" />
        <xs:attribute name="hreflang" type="xs:string" use="optional" />
        <xs:attribute name="media" type="xs:string" use="optional" />
        <xs:attribute name="type" type="xs:string" use="optional" />
        <xs:attribute name="sizes" type="xs:string" use="optional" />
    </xs:complexType>
    <!-- "help" is an IANA-defined link relation name. -->
    <xs:complexType name="HelpLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required" fixed="help" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <!-- Link relation type for a service document. -->
    <xs:complexType name="ServiceDocumentLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/a42/serviceDocument" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <xs:complexType abstract="true" name="ResourceType">
        <xs:complexContent>
            <xs:extension base="tns:ExtensibleType">
                <!-- The internal ID of this resource. -->
                <xs:attribute name="id" type="xs:string" use="optional" />
                <!-- Complete ID of this resource as URN. -->
                <xs:attribute name="urn" type="xs:string" use="optional" />
                <!-- Selflink to the resource. -->
                <xs:attribute name="selflink" type="xs:anyURI" use="optional" />
                <!-- Timestamp of the creation of this resource. -->
                <xs:attribute name="createdAt" type="xs:dateTime" use="optional" />
                <!-- Timestamp of the last update of this resource. -->
                <xs:attribute name="updatedAt" type="xs:dateTime" use="optional" />
                <!-- Link to the condensed (items as their links) representation of this resource (cet. par.), regular case. -->
                <xs:attribute name="condensedLink" type="xs:anyURI" use="optional" />
                <!-- Link to the exploded (items as their representations) representation of this page (cet. par.), exceptional case and
                    isn't always possible or even meaningful and doesn't necessarily have to be supported by each resource. In particular,
                    there MUST NOT be any cascading of explosions to referenced resources. -->
                <xs:attribute name="explodedLink" type="xs:anyURI" use="optional" />
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType abstract="true" name="PaginatableResourceType">
        <xs:complexContent>
            <xs:extension base="tns:ResourceType">
                <!-- Link to the first page (cet. par.). -->
                <xs:attribute name="firstLink" type="xs:anyURI" use="optional" />
                <!-- Link to the last page (cet. par.). -->
                <xs:attribute name="lastLink" type="xs:anyURI" use="optional" />
                <!-- Link to the previous page (cet. par.). -->
                <xs:attribute name="previousLink" type="xs:anyURI" use="optional" />
                <!-- Link to the next page (cet. par.). -->
                <xs:attribute name="nextLink" type="xs:anyURI" use="optional" />
                <!-- Number of items in the current page. -->
                <xs:attribute name="localItems" type="xs:int" use="optional" />
                <!-- Number of items in all pages. -->
                <xs:attribute name="totalItems" type="xs:int" use="optional" />
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- Container for error messages and descriptions. It's possible, but not necessary to implement this as a resource. In either case, an
        implementation should populate the "id" attribute to provide a correlation between the error representation and a log file. -->
    <xs:element name="error">
        <xs:complexType>
            <xs:complexContent>
                <xs:extension base="tns:ResourceType">
                    <xs:sequence>
                        <!-- A brief message describing the error condition. -->
                        <xs:element name="message" type="xs:string" minOccurs="1" maxOccurs="1" />
                        <!-- A longer description with information on how to fix the error condition, if applicable. -->
                        <xs:element name="description" type="xs:string" minOccurs="1" maxOccurs="1" />
                        <!-- Even more details as a collection of (key, value) pairs. -->
                        <xs:element name="details" type="tns:KeyValueCollectionType" minOccurs="0" maxOccurs="1" />
                    </xs:sequence>
                    <!-- A link that can provide help on solving the issue, e.g. documentation and the like. -->
                    <xs:attribute name="helpLink" type="xs:anyURI" use="optional" />
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
    </xs:element>

    <xs:element name="task" type="tns:TaskType" />
    <xs:complexType name="TaskType">
        <xs:complexContent>
            <xs:extension base="tns:ResourceType">
                <xs:sequence>
                    <xs:element name="type" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <xs:element name="status" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <xs:element name="message" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <xs:element name="progress" type="xs:unsignedByte" minOccurs="0" maxOccurs="1" />
                    <xs:element name="pingAfter" type="xs:dateTime" minOccurs="0" maxOccurs="1" />
                    <xs:element name="sourceLink" type="tns:LinkType" minOccurs="0" maxOccurs="1" />
                    <xs:element name="expiresAt" type="xs:dateTime" minOccurs="0" maxOccurs="1" />
                    <xs:element name="completedAt" type="xs:dateTime" minOccurs="0" maxOccurs="1" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

</xs:schema>
